import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'
import Layout from '@/layouts/index.vue'

const constantRoutes: Array<RouteRecordRaw> = [
  {
    path: '/about',
    name: 'About',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  }
]

const asyncRoutes: Array<RouteRecordRaw> = [
  {
    path: '/',
    name: '系统构建',
    component: Layout,
    redirect: '/build',
    children: [
      {
        path: 'build',
        name: '服务构建',
        component: () => import('@/views/servicesInfo/index.vue')
      },
      {
        path: 'sql',
        name: '数据库构建',
        component: () => import('@/views/sqlbuild/index.vue')
      }
    ]
  },
  {
    path: '/about',
    name: '帮助',
    component: Layout,
    redirect: '/about/readme',
    children: [
      {
        path: 'readme',
        name: '帮助',
        component: () => import('@/views/help/index.vue')
      },
      {
        path: 'q',
        name: '帮助1',
        component: () => import('@/views/help/index.vue')
      }
    ]
  }
  // {
  //   path: '/test',
  //   name: '测试菜单',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'index',
  //       name: '菜单1',
  //       component: () => import('@/views/InterfaceShow/index.vue')
  //     },
  //     {
  //       path: 'test1',
  //       name: '菜单2',
  //       component: () => import('@/views/servicesInfo/index.vue')
  //     }
  //   ],
  //   redirect: 'index'
  // }
]

function buildRoute(): RouteRecordRaw[] {
  const result: RouteRecordRaw[] = []
  constantRoutes.forEach(item => {
    result.push(item)
  })
  asyncRoutes.forEach(item => {
    result.push(item)
  })
  console.log(result)
  return result
}

const router = createRouter({
  history: createWebHashHistory(process.env.BASE_URL),
  routes: buildRoute()
})

export { asyncRoutes }

export default router
